- content_for :javascript do
  initialize_listing_view('#{I18n.locale}');

- content_for :extra_javascript do
  :javascript
    window.ST.listing({
    fuzzy_location: #{@current_community.fuzzy_location.to_json},
    listing_location: #{raw @listing.location.to_json}
    });
  - if @current_community.fuzzy_location
    - maps_key = MarketplaceHelper.google_maps_key(@current_community.id)
    = javascript_include_tag "//maps.googleapis.com/maps/api/js?key=#{maps_key}"

- content_for :title, raw(@listing.title)
- content_for :meta_author, PersonViewUtils.person_display_name(@listing.author, @current_community)
- content_for :meta_description, StringUtils.first_words(@listing.description, 15)
- content_for :meta_image, @listing.listing_images.first.image.url(:medium) if !@listing.listing_images.empty?
- dimensions = @listing.listing_images.first.get_dimensions_for_style(:medium) if !@listing.listing_images.empty?
- content_for :meta_image_width, dimensions[:width].to_s if !@listing.listing_images.empty?
- content_for :meta_image_height, dimensions[:height].to_s if !@listing.listing_images.empty?

- content_for :title_header do
  %h1
    %span#listing-title.listing-title= @listing.title

%script{type: "text/template", class: "template", id: "image-frame-template"}
  .listing-image-frame
    #listing-image-link.listing-image-frame-content
      .listing-image-vertical-centering{:class => "${aspectRatioClass}" }
        %img{:src => "${url}", :alt => @listing.title, :class => "listing-image ${aspectRatioClass}"}

%script{type: "text/template", class: "template", id: "image-thumbnail-template"}
  .listing-image-thumbnail-container
    %img.listing-image-thumbnail{src: "${url}"}
    .fade

= render partial: 'layouts/onboarding_popup_wrapper'

.row
  .col-8.listing-details-container
    .row
      .col-12
        - with_image_frame(@listing) do |reason, listing_images|
          - if reason == :images_ok
            .listing-image-carousel
              #listing-image-frame

              - if @listing_presenter.prev_image_id && @listing_presenter.next_image_id
                = link_to params.permit(:id, :locale).merge(image: @listing_presenter.prev_image_id), class: "listing-image-navi listing-image-navi-left", id: "listing-image-navi-left" do
                  .listing-image-navi-arrow-container
                    .listing-image-arrow-icon-container.left
                      = icon_tag("directleft", ["navigate-icon-fix", "listing-image-navi-arrow"])
                = link_to params.permit(:id, :locale).merge(image: @listing_presenter.next_image_id), class: "listing-image-navi listing-image-navi-right", id: "listing-image-navi-right" do
                  .listing-image-navi-arrow-container
                    .listing-image-arrow-icon-container.right
                      = icon_tag("directright", ["navigate-icon-fix", "listing-image-navi-arrow"])
            #thumbnail-stripe.listing-image-thumbnail-stripe

            - content_for :extra_javascript do
              :javascript
                var listingImages = #{raw listing_images.map { |image| ListingImageJsAdapter.new(image) }.to_json }
                var currentImage = #{params[:image].present? ? params[:image].to_i : listing_images.first.id};
                ST.listingImages(listingImages, currentImage);
          - else
            .listing-image-text-container
              .listing-image-frame
                .listing-image-frame-content
                  .listing-image-vertical-centering
                    .listing-no-image
                      - if reason == :images_processing
                        = t("listings.show.processing_uploaded_image")
                      - else
                        = t(".no_description")

    .row
      .col-12.listing-description-content
        - if @listing.description && !@listing.description.blank?
          = markdown(@listing.description)
          - if( @listing_presenter.youtube_link_ids.present?)
            - @listing_presenter.youtube_link_ids.each do |youtube_id|
              .listing-description-youtube-wrapper
                %iframe.listing-description-youtube-iframe{ title: t("listings.show.youtube_video_player"), width: 640, height:390, src: "//www.youtube.com/embed/#{ youtube_id }", frameborder: 0, allowfullscreen: true}

    - @listing.custom_field_values.each do |custom_field_value|
      .row
        .col-12
          - custom_field_value.with_type do |question_type|
            = render :partial => "listings/custom_field_partials/#{question_type}", :locals => { :custom_field_value => custom_field_value }

    - if @current_community.show_listing_publishing_date?
      .row
        .col-12
          .icon-with-text-container
            = icon_tag("calendar", ["icon-part"])
            .text-part
              %b
                = t(".listing_created_at")
                = l @listing.created_at, :format => :short_date

    - if !@current_community.private?
      .row
        .col-12
          .listing-social
            .listing-fb-like-button
              = facebook_like(current_user?(@listing.author))
            .listing-tweet-button
              - twitter_params =  {count: "horizontal", via: (@current_community.twitter_handle), text: @listing.title }.compact
              = link_to("", "https://twitter.com/share", :class => "twitter-share-button", "data" => twitter_params)
              - content_for :extra_javascript do
                :javascript
                  !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");

    - unless (@listing.closed? && !current_user?(@listing.author)) || !@current_community.listing_comments_in_use
      .view-item
        #comments.discussion.overflow-allowed
          %h2
            = icon_tag("chat_bubble", ["icon-with_text"])
            .text-with-icon
              = t(".comments")
              %span#comment_count= "(#{@listing.comments_count})"
          #follow-links.follow-links
            = render :partial => "follow_links"
          #comment-list
            = render :partial => "comment", :collection => @listing.comments
          #comment-form
            = render :partial => "comment_form"

  %aside.col-4
    - if @listing.price
      .row
        .col-12
          .listing-price
            %span.listing-price-amount
              = MoneyViewUtils.to_humanized(@listing.price)
            - with_quantity_text(@current_community, @listing) do |text|
              %span.listing-price-quantity
                = text

    .row-with-divider
      .col-12
        #listing-message-links
          = render :partial => "listing_actions"

    .row-with-divider
      .col-12
        .listing-author
          .listing-author-avatar
            = medium_avatar_thumb(@listing.author, {:class => "listing-author-avatar-image"})
          .listing-author-details
            .listing-author-name
              = link_to PersonViewUtils.person_display_name(@listing.author, @current_community), @listing.author, :id => "listing-author-link", :class => "listing-author-name-link", :title => "#{PersonViewUtils.person_display_name(@listing.author, @current_community)}"
            - if @listing.author != @current_user && @current_community.allow_free_conversations?
              .listing-author-contact
                %a#listing-contact{href: contact_to_listing_path(:listing_id => @listing.id.to_s), :class => "listing-author-contact-button"}
                  .content
                    = t(".contact")

    - if @listing_presenter.received_testimonials.size > 0
      .row-with-divider.listing-author-activity
        .col-12
          %i.listing-author-activity-icon{:class => icon_class("testimonial")}
          .listing-author-activity-item
            .listing-author-activity-value
              - if @listing_presenter.received_testimonials.size > 0
                = @listing_presenter.feedback_positive_percentage.to_s + "%"
                = t("people.show.positive")
                = "(#{@listing_presenter.received_positive_testimonials.size}/#{@listing_presenter.received_testimonials.size})"
              - else
                = t(".no_reviews")
            .listing-author-activity-description
              = t(".feedback")

    - if show_location? && @listing.origin_loc && @listing.origin_loc.address != ""
      .row
        .col-12
          #googlemap
            = render :partial => "googlemap", :locals => { :listing => @listing}
            = render :partial => "origin", :locals => { :origin_loc => @listing.origin_loc }
